package main

import (
	"fmt"
	"io"
	"io/ioutil"
	"net/http"
)

func httpclient(method string, url string, body io.Reader) error {
	//1. New一个请求体
	request, err := http.NewRequest(method, url, body)
	if err != nil {
		return err
	}
	// 2.设置请求头
	request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
	// 3. New http client
	client := http.Client{}
	// 4.发送请求
	response, err := client.Do(request)
	if err != nil {
		return err
	}
	// 5.处理回复体response
	responsedata, err := ioutil.ReadAll(response.Body)
	if err != nil {
		return err
	}
	fmt.Println(string(responsedata))
	return nil
}

func main() {
	httpclient("POST", "localhost:9900", nil)
}